package assignment2;

import java.util.Date;

/***
 * This class is used in the function getHistory and represent as pair of <title,viewtime>.
 */
public class HibernatePair {
	
	private String title;
	private Date viewtime;
	
	/***
	 * Public constructor.
	 * @param title - String, the title.
	 * @param viewtime - Date, the viewtime.
	 */
	public HibernatePair(String title, Date viewtime){
		this.title = title.toString();
		this.viewtime = new Date(viewtime.getTime());
	}

	/***
	 * Returns a String object representing this Pair's title.
	 * @return a String representing the title.
	 * @see setTitle(String title)
	 */
	public String getTitle() {
		return title;
	}

	/***
	 * Sets a String object representing this Pair's title.
	 * @param title - String, the Pair's title.
	 * @see getTitle()
	 */
	public void setTitle(String title) {
		this.title = title.toString();
	}

	/***
	 * Returns a Date object representing this Pair's viewtime value.
	 * @return a Date representing the viewtime value.
	 * @see setViewtime(Date viewtime)
	 */
	public Date getViewtime() {
		return viewtime;
	}

	/***
	 * Sets a Date object representing this Pair's viewtime value.
	 * @param viewtime - Date, the Pair's viewtime.
	 * @see getTitle()
	 */
	public void setViewtime(Date viewtime) {
		this.viewtime = new Date(viewtime.getTime());
	}
	
	@Override
	public String toString() {
		return "HibernatePair [title=" + title + ", viewtime=" + viewtime + "]";
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof HibernatePair)) {
			return false;
		}
		HibernatePair other = (HibernatePair) obj;
		if (title == null) {
			if (other.title != null) {
				return false;
			}
		} else if (!title.equals(other.title)) {
			return false;
		}
		if (viewtime == null) {
			if (other.viewtime != null) {
				return false;
			}
		} else if (!viewtime.equals(other.viewtime)) {
			return false;
		}
		return true;
	}
	
	
}
